<?php
namespace Home\Controller;
use Think\Controller;
class BackstageController extends \Home\Controller\CommonController {
	 
	 /**
     * 展示添加医院表单
     */
	public function addHospital()
    {
        //获得省列表
        $province = new \Home\Model\ProvinceModel();
        $provinceList = $province->getProvinceList();
        $this->assign('provinceList',$provinceList);
        //获的省对应的城市列表
        $activeProvince = current($provinceList);
        if(isset($activeProvince['pro_id']))
        {
            $city = new \Home\Model\CityModel();
            $cityList = $city->getCityListByProId($activeProvince['pro_id']);
            $this->assign('cityList',$cityList);
        }
        //获得医院等级
        $level = new \Home\Model\LevelModel();
        $levelList = $level->getLevelList();
        $this->assign('levelList',$levelList);
        $this->display('addHospital');
    }

     /**
     * 展示添加医生表单
     */
    public function addDoc()
    {
        //获得省列表
        $province = new \Home\Model\ProvinceModel();
        $provinceList = $province->getProvinceList();
        $this->assign('provinceList',$provinceList);
        //获的省对应的城市列表
        $activeProvince = current($provinceList);
        if(isset($activeProvince['pro_id']))
        {
            $city = new \Home\Model\CityModel();
            $cityList = $city->getCityListByProId($activeProvince['pro_id']);
            $this->assign('cityList',$cityList);
        }
        //获的医院列表
        $activeCity = current($cityList);
        if(isset($activeCity['city_id']))
        {
            $hospital = new \Home\Model\HospitalModel();
            $hospitalList = $hospital->getHospitalListByCityId($activeCity['city_id']);
            $this->assign('hospitalList',$hospitalList);
        }
        //获得医院等级
        $level = new \Home\Model\LevelModel();
        $levelList = $level->getLevelList();
        $this->assign('levelList',$levelList);
        $this->display('addDoc');
    }

     /**
     * 对添加医院的表单处理
     */
    function addHospitalForm()
    {
        $hospital = new \Home\Model\HospitalModel();
        $addRes = $hospital->addHospital();
        header('Location:'.U('Backstage/addHospital'));
    }
    // 对添加医生的表单处理
    function addDocForm()
    {
        $doctor = new \Home\Model\DoctorModel();
        $addRes = $doctor->addDoc();
        header('Location:'.U('Backstage/addDoc'));
    }


      /**
     * 显示医院修改页面  //没什么卵用
     */
    function updateHospital()
    {
        
        if(empty($_GET['hosId']))
        {
            echo "错误";
            die();
        }
        //获得当前医院信息
        $hospitalInfo = \Home\Model\HospitalModel::getHospitalDetail(I('get.hosId'));//M('hospital')->where(array('hos_id'=>I('get.hosId')))->find();

        $this->assign('hospitalInfo',$hospitalInfo);

        //获得省列表
        $province = new \Home\Model\ProvinceModel();
        $provinceList = $province->getProvinceList();
        $this->assign('provinceList',$provinceList);
        //获的省对应的城市列表
        $activeProvince = $hospitalInfo['pro_id'] ? $hospitalInfo : current($provinceList);
        if(isset($activeProvince['pro_id']))
        {
            $city = new \Home\Model\CityModel();
            $cityList = $city->getCityListByProId($activeProvince['pro_id']);
            $this->assign('cityList',$cityList);
        }
        //获得医院等级
        $level = new \Home\Model\LevelModel();
        $levelList = $level->getLevelList();
        $this->assign('levelList',$levelList);


        $this->display('updateHospital');
    }

     /**
     * 修改表单处理
     */
    function updateHospitalForm()
    {
        $data = array(
            'hos_name'=>I('post.hos_name'),
            'hos_tel_1'=>I('post.hos_tel_1'),
            'hos_tel_2'=>I('post.hos_tel_2'),
            'hos_introduction'=>I('post.hos_introduction'),
            'hos_detailed_address'=>I('post.hos_detailed_address'),
            'hos_sort'=>I('post.hos_sort'),
            'pro_id'=>I('post.province'),
            'city_id'=>I('post.city'),
            'lev_id'=>I('post.level'),
            'hos_route'=>I('post.hos_route'),
            'hos_description'=>I('post.hos_description'),
            'hos_docter'=>I('post.hos_docter'),
            'image_check'=>I('post.image_check')
        );
        dump(\Home\Model\HospitalModel::updateHospitalForId(I('post.hos_id'),$data));
    }

        // 友情链接列表and新增
    function listdateLink(){
        // $linkmain = M('link')->select();
        // var_dump($linkmain);
        $this->assign('linkmain',M('link')->select());
        $this->display('listdateLink');
    }

    function adddateLink(){
        $User = M('link');
        $User->create();
        if($User->create()){
            $result = $User->add(); // 写入数据到数据库 
            if($result){
                // 如果主键是自动增长型 成功后返回值就是最新插入的值
                $insertId = $result;
                $this->redirect('Backstage/listdateLink');
            }
        }
    }

    function deldateLink(){
        // var_dump($_GET['link_id']);
        M('link')->where(array('link_id'=>$_GET['link_id']))->delete();
        $this->redirect('Backstage/listdateLink');
    }

    /**
     * 修改友情链接处理
     */
    function updateLink()
    {
        $linkInfo = M('link')->where(array('link_id'=>$_GET['link_id']))->find();
        $this->assign('linkInfo',$linkInfo);
        $this->display('updateLink');
    }

    function updateLinkForm()
    {
        $User = M('link');
        $User->create();
        $User->save();
        $this->redirect('Backstage/listdateLink');
    }


    /**
     * 医院文章添加//↓没什么用
     */
    public function addWlist(){
        $User_sheng = M("hospital");
        $sheng = $User_sheng->select();
        $this->assign('proname',$sheng);
        $this->display('addWlist');
    }
    public function addWlistover(){
        $User = M("art"); // 实例化User对象
        $User->create();
        $result=$User->add(); // 根据条件保存修改的数据

        if($result){
        $this->success('新增成功', 'addWlist');
        } 
        else {
        $this->error('新增失败');
        }
    }
    public function Wlistlist(){
        $User = M("art"); 
        $artlist = $User->select();
        // dump($artlist);
        $this->assign('artlist',$artlist);
        $this->display('Wlistlist');
    }
     public function Wlistdel(){
        $User = M("art");
        $data['art_id'] = $_GET['artid'];
        $User->where($data)->delete(); 
    }
   public function Wlistup(){
        $User = M("hospital");
        $hosname = $User->select();
        $this->assign('hosname',$hosname);
     	$Userup = M("art"); 
        $data['art_id'] = $_GET['artid'];
        dump($data);
        $doctor = $Userup->where($data)->find();
      	$this->assign('doctor',$doctor);
      	$this->display('Wlistup');
    }
    public function Wlistsave(){
        $User = M("art"); // 实例化User对象
        // 根据表单提交的POST数据创建数据对象
        $User->create();
        $User->save();
    }

    /**
     * 医院地区添加
     */
    // public function addregion(){
    //     $cith = M("city");
    //     $pro = M("province");

    //     $shenglist = $pro->select();
    //     $this->assign('shenglist',$shenglist);
    //     // echo "<pre>";
    //     // print_r($shenglist);
    //     // echo "</pre>";
    //     $this->display();
    // }
    // public function addregionover(){
    //     $cith = M("city");
    //     $pro = M("province");
    // }
}